/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Handlers;
 
import gui.Main;
import ObjectClass.Certificate;
import ObjectClass.SQLCommunication;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Jeppe
 */
public class CertificateHandler {

    private final static String TABEL = "Certificate";
    private SQLCommunication sqlc;
    private ArrayList<Certificate> certificateList;

    public CertificateHandler(Main main) {
        this.sqlc = main.getSql();
        certificateList = new ArrayList<>();
    }

    private void instantierCertificateList() {
        certificateList.clear();
        int ID;
        String cType;
        
        String sql = "SELECT * FROM " + TABEL;
        ResultSet rs = sqlc.select(TABEL, sql);
        try {
            while (rs.next()) {
                ID = rs.getInt("ID");
                cType = rs.getString("cType");
                
                Certificate certificate = new Certificate(ID, cType);
                certificateList.add(certificate);
            }
        } catch (SQLException ex) {
            System.out.println("Der er sket en fejl i forbindelse md instantiering af certifikatList");
        }
    }
    
    public Certificate getCertificateByID(int ID){
        Certificate certificate = null;
        for (int i = 0; i < certificateList.size(); i++) {
            if(certificateList.get(i).getID() == ID){
                certificate = certificateList.get(i);
            }
        }
        return certificate;
    }
}
